import request from '@/utils/request'

export function getTableData(tableName, params, map) {
  let url = tableName+'/list/condition'
  if (map && map.length != 0) {
    for (const key in map) {
      params[key] = map[key]
    }
  }
  return request({
    url: url,
    method: 'post',
    params
  })
}
export function getDataByCondition(tableName, params) {
  let url = tableName+'/list/condition'
  return request({
    url: url,
    method: 'post',
    params
  })
}

export function initFieldConfig(tableName) {
  const params ={ 'table_name': tableName }
  return request({
    url: 'table_field/list',
    method: 'get',
    params
  })
}
export function initDict(tableName) {
  return request({
    url: 'dict/'+tableName,
    method: 'get'
  })
}
export function save(tableName, data) {
  return request({
    url: tableName+'/save',
    method: 'post',
    data
  })
}

export function del(tableName, id) {
  return request({
    url: tableName+'/'+id,
    method: 'delete'
  })
}

export function batchDelete(tableName, ids) {
  return request({
    url: tableName+'/batch/'+ids,
    method: 'delete'
  })
}

export function commonPost(url, data) {
  return request({
    url: url,
    method: 'post',
    data
  })
}
